﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Senthil.Mobile.WhereAmI
{
    [Serializable]
    public class LocationGroup
    {
        string name;
        bool isSpecial;
        List<Location> locations = new List<Location>();

        public LocationGroup(string name)
            : this(name, false)
        {
        }

        public LocationGroup(string name, bool isSpecial)
        {
            this.name = name;
            this.isSpecial = isSpecial;
        }

        public LocationGroup() { }

        public bool IsSpecial
        {
            get { return isSpecial; }
            set { isSpecial = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public Location[] Locations
        {
            get { return locations.ToArray(); }
            set
            {
                RemoveAllLocations();
                foreach (Location location in value)
                {
                    AddLocation(location);
                }
            }
        }

        public void AddLocation(Location location)
        {
            locations.Add(location);
            location.LocationGroup = this;
        }

        public void InsertFirst(Location location)
        {
            locations.Insert(0, location);
            location.LocationGroup = this;
        }

        public void RemoveLocation(Location location)
        {
            location.LocationGroup = null;
            locations.Remove(location);
        }

        public void RemoveAllLocations()
        {
            foreach (Location location in locations)
            {
                location.LocationGroup = null;
            }

            locations.Clear();
        }
      
        public override string ToString()
        {
            return this.Name;
        }
    }
}
